// pages/profit/index.js
var common = require("../../../public")
Page({

    /**
     * 页面的初始数据
     */
    data: {
        pro:[],
        isLoading:true,//如果没有数据，默认为true,表设计正在加载中
        page:0, //默认第一页
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        var that = this
        common.getLocalUserInfo(function (success, data) {
            if (success) {
              that.setData({
                userInfo: data.user,
                token: data.token,
                openid:data.openid,
             
              }, function () {
                this.getData(true)  //获取这张会员卡的信息
             
              })
            } else {
             
              that.setData({
                userInfo: null,
                token: '',
              })
            }
          },true)
    },


    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },
    getData(refresh=false){
        const that = this
        var pages = that.data.page+1
        common.get('/userDeposit/getuserDepositDetails', { 
            userId:this.data.userInfo.id,
            token:this.data.token,
            page: refresh ? 1 : pages  
        }, res => {
          if(res.status==200){
           
            if(refresh){
              that.setData({
                pro:res.data.use_details,
                page:pages
              })
             }else{
               that.setData({
                 pro:[...that.data.pro,...res.data.use_details]
               })
             }
          }else{
            that.setData({
              isLoading :false
            })
          }
           
       },()=>{
         that.setData({
           isLoading :false
         })
       })
         
    
    },
    onPullDownRefresh: function () {
      console.log("触底了")
  },
    onReachBottom: function () {
        // // 如果触底就要加载下一页数据 1236
        console.log("底部")
        // const that = this
        this.getData(false)  //获取这张会员卡的信息
        
    },
})